package com.xinxin.datastructure.stack.impl;

import com.xinxin.datastructure.array.Array;
import com.xinxin.datastructure.stack.Stack;

/**
 * @author ：史鑫鑫
 * @date ：Created in 2019/4/23 9:05
 */
public class ArrayStack<E> implements Stack<E> {
    private Array<E> array;

    public ArrayStack(int capacity) {
        array = new Array<E>(capacity);
    }

    public ArrayStack() {
        array = new Array<E>();
    }

    @Override
    public E peek() {
        return array.getLast();
    }

    @Override
    public E pop() {
        return array.removeLast();
    }

    @Override
    public void push(E e) {
        array.addLast(e);
    }

    @Override
    public boolean isEmpty() {
        return array.isEmpty();
    }

    @Override
    public int getSize() {
        return array.getSize();
    }

    public int getCapacity() {
        return array.getCapacity();
    }

    @Override
    public String toString() {
        return String.format("Stack: size = %d, capacity = %d\n",
                array.getSize(), array.getCapacity()) +
                array + " top";
    }
}
